//app.js
App({
  onLaunch: function () {
    
    if(!wx.getStorageSync('openid')){
      this.getOpenid()
    //  console.log(wx.getStorageSync('openid'))
    }else{
     // console.log(wx.getStorageSync('openid'))

    }
  },

  getOpenid(){
    var t = this
    wx.login({
      success: function(res) {
        var appid = 'wx53d35d56d39587c2'
        var secret = '2546b893b238ff0ee24e014039d1f58b'
      //  var ourl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + secret + "&js_code=" + res.code + "&grant_type=authorization_code"
        if (res.code) {
          wx.request({
            url:'https://photo.tobeyoung.net/Album.aspx',
            data: {
              code:res.code,
              GetTypes:'Get_Openid',
            },
            success:function(res){
           //   console.log(res)
              wx.setStorageSync('openid',res.data.openid)
            }
          })
        } else {
          console.log(4)
          console.log('获取用户登录态失败！' + res.errMsg)
        }
      }
    })
  },

  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            withCredentials:true,
            success: function (res) {
           //   console.log(res)
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  globalData:{
    userInfo:null,
    url:'http://photo.tobeyoung.net/Album.aspx',
    urls:'https://photo.tobeyoung.net/Album.aspx',
    domain:'https://photo.tobeyoung.net',
    System_Img_Url:'https://photo.tobeyoung.net/Sites/Site34/Album/system/'
  }
})